package com.amuse.amuse.service.impl;

import com.amuse.amuse.entity.log;
import com.amuse.amuse.entity.students;
import com.amuse.amuse.service.UserLoginService;
import com.amuse.amuse.utils.BCryptUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserLoginServiceImpl implements UserLoginService {
    @Autowired
    private com.amuse.amuse.mapper.user_login.UserLoginDao userLoginDao;
    //日志
    private static final Logger logger = LoggerFactory.getLogger(log.class);

    private String password;
    //登录
    @Override
    public students studentLogin(Integer studentId, String password) {
        //检验输入的学号是否符合格式，为6位数字

        if (studentId.toString().length() != 6) {
            return null;
        }else if ( BCryptUtils.verifyPassword(password,userLoginDao.getPassword(studentId))) {
            return userLoginDao.studentLogin(studentId,userLoginDao.getPassword(studentId));
        }

        logger.error("用户名或密码错误");
        return null;
    }

    @Override
    public Integer studentRegister(Integer studentId, String password, String name, String className, String grade, String courseType) {
        this.password = (BCryptUtils.encryptPassword(password));
        return userLoginDao.studentRegister(studentId,this.password,name,className,grade,courseType);
    }


}
